package net.esj.basic.core.engine.util.tree;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.esj.basic.pojo.TreeStructure;
import net.esj.basic.utils.CollectionUtils;

public class VoTreeConverter implements TreeConverter {

	@Override
	public <T extends TreeStructure> Collection convert(Collection<T> treeList) {
		List<TreeVo> list = new ArrayList<TreeVo>();
		for(TreeStructure tree : treeList){
			list.add(convertToTreeVo(tree));
		}
		return list;
	}
	
	protected TreeVo convertToTreeVo(TreeStructure tree){
		TreeVo vo = new TreeVo();
		if(!CollectionUtils.isEmpty(tree.getChildNodes())){
			vo.setChildNodes(convert(tree.getChildNodes()));
		}
		vo.setHasCheckBox(tree.hasCheckBox());
		vo.setHasChildNode(tree.hasChildNode());
		vo.setNodeClsIcon(tree.getNodeClsIcon());
		vo.setNodeExpansion(tree.isNodeExpansion());
		vo.setNodeId(tree.getNodeId());
		vo.setNodeLoadType(tree.getNodeLoadType());
		vo.setNodeTitle(tree.getNodeTitle());
		vo.setSelectCascade(tree.isSelectCascade());
		if(tree.getParentNode()!=null){
			vo.setParentNode(convertToTreeVo(tree.getParentNode()));
		}
		return vo;
	}
	
	public static class TreeVo implements TreeStructure{

		private Serializable nodeId;
		private Collection<TreeVo> childNodes;
		private String nodeClsIcon;
		private Integer nodeLoadType;
		private String nodeTitle;
		private TreeVo parentNode;
		private Boolean hasCheckBox;
		private Boolean hasChildNode;
		private Boolean nodeExpansion;
		private Boolean selectCascade;
		public Serializable getNodeId() {
			return nodeId;
		}
		public void setNodeId(Serializable nodeId) {
			this.nodeId = nodeId;
		}
		public Collection<TreeVo> getChildNodes() {
			return childNodes;
		}
		public void setChildNodes(Collection<TreeVo> childNodes) {
			this.childNodes = childNodes;
		}
		public String getNodeClsIcon() {
			return nodeClsIcon;
		}
		public void setNodeClsIcon(String nodeClsIcon) {
			this.nodeClsIcon = nodeClsIcon;
		}
		public Integer getNodeLoadType() {
			return nodeLoadType;
		}
		public void setNodeLoadType(Integer nodeLoadType) {
			this.nodeLoadType = nodeLoadType;
		}
		public String getNodeTitle() {
			return nodeTitle;
		}
		public void setNodeTitle(String nodeTitle) {
			this.nodeTitle = nodeTitle;
		}
		public TreeVo getParentNode() {
			return parentNode;
		}
		public void setParentNode(TreeVo parentNode) {
			this.parentNode = parentNode;
		}
		public Boolean hasCheckBox() {
			return hasCheckBox;
		}
		public void setHasCheckBox(Boolean hasCheckBox) {
			this.hasCheckBox = hasCheckBox;
		}
		public Boolean hasChildNode() {
			return hasChildNode;
		}
		public void setHasChildNode(Boolean hasChildNode) {
			this.hasChildNode = hasChildNode;
		}
		public Boolean isNodeExpansion() {
			return nodeExpansion;
		}
		public void setNodeExpansion(Boolean nodeExpansion) {
			this.nodeExpansion = nodeExpansion;
		}
		public Boolean isSelectCascade() {
			return selectCascade;
		}
		public void setSelectCascade(Boolean selectCascade) {
			this.selectCascade = selectCascade;
		}
		
	}

}
